import getApiData from "@/services/cpasRequest";
import notify from 'devextreme/ui/notify';
// import { getApisData } from "../../services/cpasRequest";
// 获取账套
export async function getAccountInfo(params: {
  dbname: string;
}) {
  if (!params.dbname) return [];
  const res = await getApiData("account.accountInfo.getDataList", params);
  if (res.ok) {
    return Promise.resolve({
      data: res.data,
      success: true,
    });
  }
  return Promise.resolve({
    data: [],
    success: false,
  });
}

// 获取截止月份的数据
export async function getAccountInfoMonthList(params: {
  dbname: string;
  Data_ID: string
}) {
  const res = await getApiData("account.accountInfo.getMonthList", params);
  return Promise.resolve({
    data: res.data,
    success: res.ok,
  });
}


// 获取左侧切换的数据
export async function getSubjectType(params: {
  dbname: string;
  Data_ID: string
}) {
  const res = await getApiData("account.subject.getType", params);
  return Promise.resolve({
    data: res.data,
    success: res.ok,
  });
}

// 获取左侧树数据
export async function getSubjectList(params: {
  dbname: string;
  Data_ID: string;
  isHasFZZ?: boolean;
}) {
  // account.subject.getDataList
  const res = await getApiData("account.subject.getDataList", params);
  return Promise.resolve({
    data: res.data,
    success: res.ok,
  });
}
// 获取右侧表格数据
// account.subjectSDB.getDataList
export async function getSubjectSDB(params: {
  dbname: string;
  Data_ID: string;
  isHasFZZ: boolean;
}) {
  const res = await getApiData("account.subjectSDB.getDataList", params);
  return Promise.resolve({
    data: res.data,
    success: res.ok,
  });
}
// 获取层级数据
export async function getSubjectLevel(params: {
  dbname: string;
  Data_ID: string;
  isHasFZZ: boolean;
}) {
  const res = await getApiData("account.subject.getLevel", params);
  if (res.ok) {
    return res.data;
  }
  return {};
}

// 获取截止日期
// account.cutOffDate.get
export async function getCutOffDate(params: {
  dbname: string;
  Data_ID: string;
}) {
  const res = await getApiData("account.cutOffDate.get", params);
  if (res.ok) {
    return res.data;
  }
  return {};
}

// 初始化科目审定表
// account.cutOffDate.get
export async function subjectSDB(params: {
  dbname: string;
  Data_ID: string;
  byMonth: string,
  isForceInit: boolean
}) {
  const res = await getApiData("account.subjectSDB.init", params);
  return res.ok;
}

// 初始化辅助账审定表
// account.cutOffDate.get
export async function assistSDB(params: {
  dbname: string;
  Data_ID: string;
  byMonth: string,
  isForceInit: boolean
}) {
  const res = await getApiData("account.assistSDB.init", params);
  return res.ok;
}

// 重新计算报表项目数据
export async function reCalReportItemsData(params: {
  dbname: string;
  Data_ID: string;
  editUser: any;
  isRecalTZ: boolean
}) {
  const res = await getApiData("account.reportItem.reCal", params);
  if (res.ok) {
    // notify("重新计算报表项目数据成功",'Success',2000)
    return res.ok;
  }
  return {};
}

// 重新计调整分录
export async function adjustingEntry(params: {
  dbname: string;
  Data_ID: string;
  editUser: any;
}) {
  const res = await getApiData("account.adjustingEntry.reCal", params);
  if (res.ok) return res.ok;
  return {};
}
//  批量请求 bug
// export async function getInitUpdata(params: {
//   dbname: string;
//   Data_ID: string
//   userName?: any;
//   byMonth: string,
//   isForceInit: boolean
// }) {
//   const paramsData = {
//       apis: [
//           { 
//               name: 'sqlApi.update',
//               params: {
//                 name: "l_dwndInfo_detail",
//                   dbName: params.dbname,
//                   Data_ID:params.Data_ID,
//                   isForceInit:params.isForceInit,
//                   byMonth:params.byMonth,
//               }
//           },
//             {
//               name: 'sqlApi.update',
//               params: {
//                 name: "l_dwndInfo_detail",
//                 dbName: params.dbname,
//                 Data_ID:params.Data_ID,
//                 isForceInit:params.isForceInit,
//                 byMonth:params.byMonth,
//             }
//           },
//     ],
//   }
//   const res = await getApisData(paramsData);
//   const resTemp = res.data['sqlApi.update']
//   console.log(resTemp,'----');
// }


// account.subjectSDB.init
export async function getDataSubjectSDB(params: {
  data: any,
  dbname: any
}) {
  console.log(params.data, 'params------------');
  const paramsData = {
    apis: [
      {
        name: 'params.TEMPLETList',
        // 私用的参数
        params: {
          year: 2021
        }
      },
      {
        name: 'params.TEMPLETList',
        // 私用的参数
        params: {
          year: 2022
        }
      },
      {
        name: 'params.TEMPLETList',
        // 私用的参数
        params: {
          year: 2022
        }
      },
      // {
      //     name: params.fourName,
      //     // 私用的参数
      //     params: {}
      // }
    ],
    reload: true,
    // 公用的参数
    params: {
      dbname: params.dbname,
    }
  }
  // const res = await getApisData(paramsData);
  // const TEMPLETList = res.data['account.subjectSDB.init']
  // // const temp3 = res.data[params.fourName]
  // if (res.ok && TEMPLETList.ok ) {
  //     return Promise.resolve({
  //         data: res.data,
  //         success: true,
  //     });
  // }
  // return Promise.resolve({
  //     data: res.data,
  //     success: false,
  // });
}

